package com.xia.netty.thread.volatileExp;

public class VolatileAddTest {
    volatile int i = 0;

    public void add() {
        i++;
    }

    public static void main(String[] args) {
        VolatileAddTest volatileAddTest = new VolatileAddTest();
        for (int i = 0; i < 1000; i++) {
            new Thread(() -> {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                volatileAddTest.add();
            }).start();

        }try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(
                volatileAddTest.i
        );



    }

}
